import 'dart:math';

import 'package:dk_flutter_base/dk_core.dart';
import 'package:flutter/widgets.dart';

class IsoscelesTrapeziumClipper extends CustomClipper<IsoscelesTrapeziumPath> {
  double deg;
  double rad;

  IsoscelesTrapeziumClipper.deg(this.deg) {
    rad = degToRad(deg);
  }

  IsoscelesTrapeziumClipper.rad(this.rad);

  @override
  IsoscelesTrapeziumPath getClip(Size size) {
    return IsoscelesTrapeziumPath.rad(size, rad).startDraw();
  }

  @override
  bool shouldReclip(CustomClipper oldClipper) {
    return true;
  }
}

class IsoscelesTrapeziumPath extends Path {
  Size size;
  double rad;
  double deg;

  IsoscelesTrapeziumPath.rad(this.size, this.rad);

  IsoscelesTrapeziumPath.deg(this.size, this.deg) {
    rad = degToRad(deg);
  }

  IsoscelesTrapeziumPath startDraw() {
    double helperLength = size.height * cos(rad);
    lineTo(size.width, 0);
    lineTo(size.width - helperLength, size.height);
    lineTo(helperLength, size.height);
    lineTo(0, 0);
    close();
    return this;
  }
}
